/**
 * Created by IntelliJ IDEA.
 * User: Ian
 * Date: Jan 17, 2011
 * Time: 6:20:55 PM
 * To change this template use File | Settings | File Templates.
 */

/**
 *
 * @param {Number} x
 * @param {Number} y
 */
  Vec2 = function(x,y) {
    var that = this;
    that.x = x;
    that.y = y;


    that.Copy = function() {
      return new Vec2(that.x, that.y);
    }

    /**
     *
     * @param {Vec2} other
     * @return {Vec2} new point
     */
    that.Add = function(other) {
      var result = new Vec2(
          that.x + other.x,
          that.y + other.y);
      return result;
    }

    /**
     *
     * @param {Vec2} other
     * @return {Vec2} new point
     */
    that.Subtract = function(other) {
      var result = new Vec2(
          that.x - other.x,
          that.y - other.y);
      return result;
    }

    that.DistanceSquaredTo = function(other) {
      var x = other.x - that.x;
      var y = other.y - that.y;

      return x * x + y * y;
    }

    that.Scale = function(scalar) {
      var result = new Vec2(that.x * scalar, that.y * scalar);
      return result;
    }


    that.Normalize = function() {
      var len = Math.sqrt(that.x*that.x + that.y*that.y);
      return that.Scale(1/len);
    }

    that.Dot = function(other) {
      return that.x * other.x + that.y * other.y;
    }
  }